package cn.tedu.tmall.server.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自动时间填充
 */
@Component
public class AutoChangeTimeInsert implements MetaObjectHandler {

    @Value("${db.mysql.field_name.create_time}")
    private String createTimeName;

    @Value("${db.mysql.field_name.update_time}")
    private String updateTimeName;

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName(createTimeName,new Date(),metaObject);
        this.setFieldValByName(updateTimeName,new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName(updateTimeName,new Date(),metaObject);
    }
}
